-- card: 31988 from stack: in.5 -- bmap block id: 35406 -- flags: 0000 -- background id: 3858 -- name: DiskSpaceAvail ----- HyperTalk script ----- on HideObjects hide cd btn "Try It!" end HideObjects on ShowObjects show cd btn "Try It!" end ShowObjects -- part 6 (button) -- low flags: 00 -- high flags: A002 -- rect: left=78 top=197 right=231 bottom=171 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 8192 -- line height: 16 -- part name: Try it! ----- HyperTalk script ----- on mouseUp put volumePath() into newVolume if newVolume = empty then exit mouseUp put DiskSpaceAvail(newVolume) into freeSpace answer freeSpace && "bytes (" & freeSpace div 1024 && "K) free on “" & newVolume & "”" end mouseUp -- part contents for background part 20 ----- text ----- This XFCN returns the amount of free space (in bytes) on a disk. It is functionally similar to HyperCard's "DiskSpace", except that it works with any mounted volume To use this demo click on the "Try It!" button. You will be presented with a dialog to select one of your mounted drives. Calling syntax : DiskSpaceAvail(volumeName, <"noDialog:"errorGlobal>) VOLUMENAME: the path to the volume to check. -- part contents for background part 38 ----- text ----- 10/50 -- part contents for background part 42 ----- text ----- { DiskSpaceAvail(volumeName «,“noDialog:”errorGlobal») } { XFCN to determin amount of free space on a volume, returns } { the number of bytes free } {} { brought to you by: Anup Murarka Eric Carlson } { ALINK: SKEPTIC ALINK: cyNic } { CIS: 76004,3356 } {} { We are part of the Support Tools Development Group, } { Apple Computer, Inc. } {} { please DO NOT contack Mac DTS for support of this code! } {} { please DO contact the authors for support of this code! } {} { Send comments, bug reports, requests to any of the above } { E-mail addresses or to:} {} { (one of us) } { Apple Computer, Inc. } { 900 E. Hamilton, Ave. } { Campbell, CA 95008 } { M/S 72-L } {} { Copyright: © 1989, 1990 by Apple Computer, Inc., all rights reserved. } {} { written by Eric Carlson } { AppleLink: cyNic } { modification history } { Date Initials Comments } { ---- ------ ------------------------------------------------------ } { 1/26/90 ec first written } { 2/14/90 ec general code cleaning } { 5/31/90 ec commented code further } { 7/2/90 ec fixed unsinged/signed conversion bug as per Tech note 157, changed version } { to 1.1 } {} unit DiskSpaceAvail; interface uses HyperXcmd; procedure MAIN (paramPtr: XCmdPtr); implementation procedure DiskSpaceAvail (paramPtr: XCmdPtr); FORWARD; procedure MAIN (paramPtr: XCmdPtr); begin DiskSpaceAvail(paramPtr); end; procedure reportToUser (paramPtr: XCmdPtr; msgStr: str255); {} { report something back to the user. } { the last parameter (optional) to an external may contain } { "noDialog" or "noDialog:GlobalName". GlobalName is the name } { of a HyperTalk global variable into which error messages will be } { placed. we've decided to use this approach to avoid confusing } { an error message with a valid result being returned from an XFCN. } {} var tempStr: str255; begin {check the last param to see if the user requested that} { we suppress the error dialog } ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr); UprString(tempStr, true); if pos('NODIALOG', tempStr) = 0 then { no special error handling specified, throw up a dialog and return the error message } begin SendCardMessage(paramPtr, concat('answer "', msgStr, '"')); paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end else if (pos(':', tempStr) > 0) then { requested global AND noDialog so we fill in the global and return empty } begin tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr)); { get the name of the HC global to fill } SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr)); { and fill it } paramPtr^.returnValue := PasToZero(paramPtr, ''); { return empty } end else { requested noDialog only so we return the error condition as the result } paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end; { procedure } function NumberToString (paramPtr: XCmdPtr; num: LONGINT): Str255; { use the toolbox call rather than HC's } var tempStr: str255; begin NumToString(num, tempStr); NumberToString := tempStr; end; procedure reportResError (paramPtr: XCmdPtr; errorNum: integer); var errMsg, tempName: str255; begin sysbeep(40); case errorNum of { what caused the problem? } bdNamErr: errMsg := 'Bad volume name.'; extFSErr: errMsg := 'External file system.'; ioErr: errMsg := 'I/O Error.'; nsDrvErr: errMsg := 'No such drive.'; nsvErr: errMsg := 'No such volume.'; paramErr: errMsg := 'You may not eject the default volume.'; otherwise errMsg := concat('unexpected error #', NumberToString(paramPtr, errorNum)); end; { case } errMsg := concat('Sorry, ', errMsg); reportToUser(paramPtr, errMsg); { return the error message } end; { function } function getParams (paramPtr: XCmdPtr; var volToFind: str255): boolean; var numParams: integer; inputCh: str255; begin getParams := true; numParams := paramPtr^.paramCount; if (numParams < 1) or (numParams > 2) then begin getParams := false; reportToUser(paramPtr, 'DiskSpaceAvail(volumeName «,“noDialog:”errorGlobal»)'); exit(getParams); end; MoveHHi(paramPtr^.Params[1]); HLock(paramPtr^.Params[1]); ZeroToPas(paramPtr, paramPtr^.Params[1]^, volToFind); HUnlock(paramPtr^.Params[1]); uprString(volToFind, true); if (volToFind = '?') or (volToFind = '') then begin getParams := false; reportToUser(paramPtr, 'DiskSpaceAvail(volumeName «,“noDialog:”errorGlobal»)'); exit(getParams); end; if (volToFind = '!') then begin getParams := false; reportToUser(paramPtr, 'v1.1, © 1990 Apple Computer, Inc., by Eric Carlson'); exit(getParams); end; end; {GetParams} function validVolumeName (volumeName: str255): str255; { a volume name must have one (and only one) colon in it, as } { the last character } begin if pos(':', volumeName) = 0 then validVolumeName := concat(volumeName, ':') else validVolumeName := copy(volumeName, 1, pos(':', volumeName)); end; procedure DiskSpaceAvail (paramPtr: XCmdPtr); type TwoIntsMakeaLong = record case integer of 1: ( long: LongInt ); 2: ( ints: array[0..1] of integer ); end; var theSpace: TwoIntsMakeaLong; getParamsOK: boolean; volToTest: str255; PB: HParamBlockRec; errorCode: OSErr; begin { fetch and validate the passed parameters} getParamsOK := getParams(paramPtr, volToTest); if not (getParamsOK) then exit(DiskSpaceAvail); volToTest := validVolumeName(volToTest); { make sure the volume name is correct } { initialize parameter block. Since volToTest is a full pathname, no other field is needed} zeroBytes(paramPtr, @PB, sizeOf(PB)); PB.ioNamePtr := @volToTest; PB.ioVolIndex := -1; errorCode := PBHGetVInfo(@PB, false); if errorCode = noErr then begin { we must change the unsinged int returned by our PBH call to a signed long ourselves as the compiler } { will sign extend it and thus make it negative - see tech note 157 } theSpace.ints[0] := 0; { clear the high word } theSpace.ints[1] := PB.ioVFrBlk; { set the low word to our value } NumToString(theSpace.long * PB.ioVAlBlkSiz, volToTest); { borrow our string var for a minute } paramPtr^.returnValue := PasToZero(paramPtr, volToTest); end else begin reportResError(paramPtr, errorCode); exit(DiskSpaceAvail); end; end; { procedure FileExists} end. { unit FileExists}